package com.example.yuejian23.yuejian_23.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejian23.yuejian_23.R;
import com.example.yuejian23.yuejian_23.activity.HuodongActivity;
import com.example.yuejian23.yuejian_23.javaBean.HuodongBean;
import com.squareup.picasso.Picasso;

import java.util.List;



public class GuanhuodongAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private LayoutInflater mlayoutInflater;
    public GuanhuodongAdapter(Context mContext, List<HuodongBean> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mlayoutInflater = LayoutInflater.from(mContext);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mlayoutInflater.from(parent.getContext()).inflate(R.layout.guanzhuhuo, parent, false);
        return new GuanhuodongAdapter.ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final HuodongBean entity = (HuodongBean) mDataList.get(position);
        if (null == entity)
            return;
        GuanhuodongAdapter.ViewHolder viewHolder = (GuanhuodongAdapter.ViewHolder) holder;
        viewHolder.name.setText(entity.getAname());
        Picasso.with(mContext).load("http://115.159.93.244/new18yuejian/Public/upload/"+entity.getActpic()).into(viewHolder.huodong_tou);


        viewHolder.guanzhuhuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                intent.setClass(mContext, HuodongActivity.class);

                bundle.putString("huodongid",entity.getClubid());
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    private class ViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        ImageView huodong_tou;
        LinearLayout guanzhuhuo;


        public ViewHolder(View v) {
            super(v);
            name = (TextView) v.findViewById(R.id.name);
            huodong_tou = (ImageView) v.findViewById(R.id.huodong_tou);
            guanzhuhuo = (LinearLayout) v.findViewById(R.id.guanzhuhuo);
        }
    }
}

